﻿﻿namespace AlphaTab.Util;

internal class Lazy<T> where T:class?
{
    private readonly System.Func<T> _factory;

    private bool _created = false;
    private T _value;

    public Lazy(System.Func<T> factory)
    {
        _factory = factory;
        _value = null!;
    }

    public T Value
    {
        get
        {
            if (!_created)
            {
                _value = _factory();
                _created = true;
            }
            return _value;
        }
    }

    public void Reset()
    {
        _created = false;
        _value = null!;
    }
}
